package com.itheima.health.controller;
import com.itheima.health.common.PageParam;
import com.itheima.health.common.R;
import com.itheima.health.common.ResultPageData;
import com.itheima.health.entity.TCheckgroup;
import com.itheima.health.model.pojos.CheckItem;
import com.itheima.health.pojo.dto.TCheckgroupDTO;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.ITCheckgroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cpanda
 * @since 2024-01-25
 */
@RestController
public class TCheckgroupController {
    /**
     * 检查组
     */
    @Autowired
    ITCheckgroupService checkgroupService;
    @Autowired
    CheckItemService checkItemService;

    /**
     * 检查组查询
     * @param pageParam
     * @return
     */
    @PostMapping("/checkgroup/findPage")
    public ResultPageData checkgroupPage(@RequestBody PageParam pageParam){
        return checkgroupService.cGPpage(pageParam);
    }
    /**
     * 检查组新增 包含检查项
     */

    @PostMapping("/checkgroup/add")
    public R add(@RequestBody TCheckgroup checkGroup, Integer[]checkitemIds) {
        checkgroupService.add(checkGroup,checkitemIds);
        return R.success(null);
    }

    /**
     * 检查组回显
     */
    @GetMapping("/checkgroup/findById")
    public R checkgroupById(Long id){
        TCheckgroup checkGroup=  checkgroupService.checkgroupById(id);
        return R.success(checkGroup);
    }
    /**
     * 回显检查组 关联检查项
     */
    @GetMapping("/checkitem/findCheckItemIdsByCheckGroupId")
    public R findCheckItemIdsByCheckGroupId(Integer checkgroupId){
        List<Integer> checkitemList= checkgroupService.findCheckItemIdsByCheckGroupId(checkgroupId);
        return R.success(checkitemList);
    }

    /**
     * 检查组检查项回显
     */
    @GetMapping("/checkitem/findAll")
    public R findCheckItemAll(){
        List<CheckItem> checkItems =checkItemService.findCheckItemAll();
        return R.success(checkItems);
    }
    /**
     *更新检查组
     */
    @PutMapping("/checkgroup/edit")
    public R updateCheckgroup(@RequestBody TCheckgroup dto,@RequestParam("checkitemIds") Integer [] checkitemIds){
        checkgroupService.updateCheckgroup(dto,checkitemIds);
        return R.success(null);
    }
    @DeleteMapping("/checkgroup/delete")
    public R checkgroupDelete(Integer id){

        checkgroupService.checkgroupDelete(id);
        return R.success(null);
    }
}
